package com.tuyan.aixiang.activity.config;

import com.ezviz.opensdk.wificonfig.EZWiFiConfigMode;
import com.ezviz.opensdk.wificonfig.EZWifiConfigStatus;
import com.tuyan.aixiang.common.BasePresenter;
import com.tuyan.aixiang.model.YsDevice;
import com.tuyan.aixiang.util.Log;
import com.videogo.openapi.EZWifiConfigManager;

public class SmartConfigPresenter extends BasePresenter<SmartConfigActivity> implements SmartConfig.Presenter {

    private static final String TAG = "SmartConfigPresenter";

    private YsDevice device;

    @Override
    public void init(YsDevice device) {
        this.device = device;
    }

    public void deviceConnect(String ssid, String pwd) {
        iView.get().showLoading();
       EZWifiConfigManager.startConfigWifi(device.getDeviceSerial(), ssid, pwd, EZWiFiConfigMode.EZWiFiConfigSmart,
               (deviceSerial, status) -> {
                   if(status ==EZWifiConfigStatus.DEVICE_WIFI_CONNECTED) {
                       // 设备wifi链接成功
                       Log.d(TAG, "device wifi connected");
                   } else if(status == EZWifiConfigStatus.DEVICE_PLATFORM_REGISTED) {
                       EZWifiConfigManager.stopConfigWiFi();
                       // 注册成功,可添加至平台
                       Log.d(TAG, "device platform registed");
                       iView.get().configSuccess();
                   } else if(status == EZWifiConfigStatus.TIME_OUT) {
                       Log.d(TAG, "device wifi config timeout");
                       iView.get().configFail();
                   }
               });

    }
}
